import { defineStore } from 'pinia';
import { store } from '@/store';
import { storage } from '@/utils/Storage';

// 定义字典项类型
export interface DictItem {
  label: string;
  value: string;
  [key: string]: any; // 允许其他属性
}

// 定义字典状态类型
export interface IDictState {
  alarmCategoryTags: DictItem[];
  reminderCategoryTags: DictItem[];
  // 可以添加更多字典类型
}

export const useDictStore = defineStore({
  id: 'app-dict',
  state: (): IDictState => ({
    alarmCategoryTags: storage.get('ALARM_CATEGORY_TAGS', []),
    reminderCategoryTags: storage.get('REMINDER_CATEGORY_TAGS', []),
  }),
  getters: {
    getAlarmCategoryTags(): DictItem[] {
      return this.alarmCategoryTags;
    },
    getReminderCategoryTags(): DictItem[] {
      return this.reminderCategoryTags;
    },
  },
  actions: {
    setAlarmCategoryTags(tags: DictItem[]) {
      this.alarmCategoryTags = tags;
      storage.set('ALARM_CATEGORY_TAGS', tags);
    },
    setReminderCategoryTags(tags: DictItem[]) {
      this.reminderCategoryTags = tags;
      storage.set('REMINDER_CATEGORY_TAGS', tags);
    },
    // 可以添加更多字典设置方法
  },
});

// Need to be used outside the setup
export function useDict() {
  return useDictStore(store);
}